package com.example.t410.service.serviceImpl;

import com.example.t410.DTO.SportDTO;
import com.example.t410.VO.SportVO;
import com.example.t410.VO.SportVideoVO;
import com.example.t410.mapper.SportImageMapper;
import com.example.t410.mapper.SportMapper;
import com.example.t410.service.SportService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SportServiceImpl implements SportService {
    @Autowired
    SportMapper sportMapper;
    @Autowired
    SportImageMapper sportImageMapper;

    /**
     * 运动基本信息查询
     * @param sportDTO
     * @return
     */
    @Override
    public List<SportVO> select(SportDTO sportDTO) {
        if(sportDTO.getStartTime()==null || sportDTO.getStartTime()<0){
            sportDTO.setStartTime(0);
        }
        if(sportDTO.getEndTime()==null || sportDTO.getEndTime()>100){
            sportDTO.setEndTime(100);
        }
        if(sportDTO.getLeague()!=null && sportDTO.getLeague()!=""){
            Long leagueId=(long)(sportDTO.getLeague().charAt(1)-'0');
            sportDTO.setLeagueId(leagueId);
        }
        List<SportVO> list=sportMapper.select(sportDTO);
        for (SportVO s:list) {
            String[] str= s.getMotion().split("-");
            List<String> motionlist=new ArrayList<>();
            for (int i = 0; i < str.length; i++) {
                motionlist.add(str[i]);
            }
            s.setMotionFeatures(motionlist);
        }
        return list;
    }

    /**
     * 详细信息查询
     * @param id
     * @return
     */
    @Override
    public SportVideoVO selectById(Long id) {
        SportVideoVO sportVideoVO=sportMapper.selectById(id);
        List<String> imageList=sportImageMapper.selectBySportId(id);
        sportVideoVO.setImageList(imageList);
        String[] str= sportVideoVO.getMotion().split("-");
        List<String> motionlist=new ArrayList<>();
        for (int i = 0; i < str.length; i++) {
            motionlist.add(str[i]);
        }
        sportVideoVO.setMotionFeatures(motionlist);
        return sportVideoVO;
    }
}
